home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pnl010.zip / MDP4.PAS < prev    next >
Pascal/Delphi Source File  |  1992-03-01  |  2KB  |  80 lines

  1. program mdp4;
  2.  
  3. {Program to accompany article in issue #10 of the Pascal NewsLetter.        }
  4. {Author: Mitch Davis, (3:634/384.6) +61-3-890-2062.                         }
  5.  
  6. {Reads up to 100 lines from a file specified on the command line, then lets }
  7. {you scroll through it using the +/- keys, and q to quit.  Note this program}
  8. {works by actually reading in the data from the file into a fixed-size array}
  9.  
  10. uses crt;
  11.  
  12. const ScreenLen:integer = 24;
  13.       MaxLines  = 100;
  14.       WinTop:integer = 1;
  15.  
  16. var line:array [1..MaxLines] of string; {This takes 25600 bytes}
  17.     LineCount:integer; {Note must be integer not word}
  18.     loop:byte;
  19.     ch:char;
  20.     f:text;
  21.  
  22.   function Min (a,b:word):word;
  23.  
  24.   {returns the smaller of the two parameters}
  25.  
  26.   begin
  27.     if a < b then Min := a else Min := b;
  28.   end;
  29.  
  30.   procedure PrLn (var s:string);
  31.  
  32.   {prints a line truncated to 79 characters - ensures that long lines }
  33.   {don't spoil the layout of the display                              }
  34.  
  35.   begin
  36.     writeln (copy (s,1,79));
  37.   end;
  38.  
  39. begin
  40.   {Read in the file}
  41.   write ('Reading...');
  42.   assign (f,paramstr (1));
  43.   reset (f);
  44.   LineCount := 0;
  45.   while not (eof (f) or (LineCount = MaxLines)) do begin
  46.     inc (LineCount);
  47.     readln (f,line [LineCount]);
  48.   end;
  49.   close (f);
  50.  
  51.   {Draw the initial screen}
  52.   clrscr;
  53.   for loop := 1 to min (ScreenLen,LineCount-WinTop+1) do prLn (line [loop]);
  54.   write ('            Use ''+'' to move forward, ''-'' to move back.  ''q'' to quit.');
  55.   repeat
  56.     ch := readkey;
  57.     case ch of
  58.       '-':if WinTop > 1 then begin
  59.             dec (WinTop);
  60.             gotoxy (1,ScreenLen);
  61.             DelLine;
  62.             gotoxy (1,1);
  63.             InsLine;
  64.             PrLn (Line[WinTop]);
  65.           end;
  66.       '+':if WinTop < LineCount-ScreenLen+1 then begin
  67.             inc (WinTop);
  68.             gotoxy (1,1);
  69.             DelLine;
  70.             gotoxy (1,ScreenLen);
  71.             InsLine;
  72.             PrLn (line[WinTop+ScreenLen-1]);
  73.           end;
  74.       'q':;
  75.       else write (#7);
  76.     end;
  77.     gotoxy (1,ScreenLen+1); write (WinTop:5,'/',LineCount);
  78.   until ch = 'q';
  79. end.
  80.